package com.vlong.town.service.comm;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vlong.town.entity.comm.CommInfo;
import com.vlong.town.mapper.comm.CommInfoMapper;

/**
 * 信息互联信息业务实现类
 * @author Assassin
 */
@Service
public class CommInfoService {

    // Fields

    @Autowired
    private CommInfoMapper commInfoMapper;// 信息互联信息Mapper接口

    // Methods

    /**
     * 添加信息互联信息
     * @param townId 村镇Id
     * @param title 信息互联标题
     * @param content 信息互联内容
     * @param desc 信息互联简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void add(Long townId, String title, String content, String desc, String thumbnail) {
        CommInfo commInfo = new CommInfo();
        commInfo.setTownId(townId);
        commInfo.setState(1);
        commInfo.setStatus(1);
        commInfo.setTitle(title);
        commInfo.setContent(content);
        commInfo.setDesc(desc);
        commInfo.setThumbnail(thumbnail);
        Long cuTime = System.currentTimeMillis();
        commInfo.setCreateTime(cuTime);
        commInfo.setUpdateTime(cuTime);
        this.commInfoMapper.insert(commInfo);
    }

    /**
     * 逻辑删除信息互联信息
     * @param noticeId 主键值
     */
    @Transactional
    public void delete(Long noticeId) {
        this.commInfoMapper.delete(noticeId);
    }

    /**
     * 修改信息互联信息
     * @param noticeId 信息互联Id
     * @param title 信息互联标题
     * @param content 信息互联内容
     * @param desc 信息互联简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void update(Long noticeId, String title, String content, String desc, String thumbnail) {
        CommInfo commInfo = new CommInfo();
        commInfo.setInfoId(noticeId);
        commInfo.setTitle(title);
        commInfo.setContent(content);
        commInfo.setDesc(desc);
        commInfo.setThumbnail(thumbnail);
        commInfo.setUpdateTime(System.currentTimeMillis());
        this.commInfoMapper.update(commInfo);
    }

    /**
     * 主键查询信息互联信息
     * @param noticeId 信息互联Id
     * @return
     */
    @Transactional(readOnly = true)
    public CommInfo queryById(Long noticeId) {
        return this.commInfoMapper.selectById(noticeId);
    }

    /**
     * 查询信息互联信息
     * @param title 信息互联标题
     * @param content 信息互联内容
     * @param desc 信息互联简介
     * @return List<CommInfo>
     */
    @Transactional(readOnly = true)
    public List<CommInfo> queryList(String title, String content, String desc) {
        CommInfo commInfo = new CommInfo();
        commInfo.setTitle(title);
        commInfo.setContent(content);
        commInfo.setDesc(desc);
        return this.commInfoMapper.selectList(commInfo);
    }

}
